/**
 * @desc 工作项目
 */

'use strict'

const MODEL_NAME = 'project'
const COLLECTION_NAME = 'projects'
const USER_MODEL_NAME = 'user'

module.exports = app => {
  const mongoose = app.mongoose
  const Schema = mongoose.Schema

  const ProjectSchema = new Schema({
    // 创建者
    owner: { type: Schema.Types.ObjectId, ref: USER_MODEL_NAME, required: true },
    // 包含的成员
    members: { type: [{ type: Schema.Types.ObjectId, ref: USER_MODEL_NAME }], default: [] },

    title: { type: String, required: true },
    desc: { type: String, default: '' },
    // 状态值,只有当所有成员的todo都完成时,才会设置为'done'
    status: { type: String, enum: ['done', 'doing'], default: 'doing' },

    // 属于自定义的属性,用来定制项目卡的样式
    bgColor: { type: String, default: '#cccccc' },
    coverUrl: { type: String, default: '' },

    createdAt: { type: Date, default: Date.now },
    updatedAt: { type: Date, default: Date.now },
  })

  return mongoose.model(MODEL_NAME, ProjectSchema, COLLECTION_NAME)
}
